<script setup lang="ts">
import {useToast} from 'vue-toast-notification';
import 'vue-toast-notification/dist/theme-sugar.css';
const $toast = useToast();//消息提示栏
import router from "@/router";
import {ref} from "vue";
import axios from "axios";

const back = () => {
  router.push("/")
}
const email = ref('')
const isSendSuccess = ref(false)
const onSubmit = () => {
  let val = email.value
  axios.get("/api/mail/initPassword?email="+email.value)
      .then(res=>{
        // console.log(res)
        if(res.data.success){
          $toast.open({
            type:"success",
            position:"bottom",
            message:"邮件发送成功"
          })
        }else{
          $toast.open({
            type:"error",
            position:"bottom",
            message:"请在"+res.data.message[val]+"秒后重试"
          })
        }
      })
}
</script>

<template>
<div class="forget-box">
  <div class="top-back">
    <q-btn outline round color="grey-4" icon="arrow_back_ios" @click="back"/>
  </div>
  <div class="text-h4" style="margin-top: 10vh;">忘记密码？</div>
  <div class="text-body1 text-center" style="margin-top: 20px;width: 40vw;">
    要找回密码，请使用与账户关联的电子邮件地址。我们将向您发送一封带有重置密码链接的电子邮件。
  </div>
  <div style="width: 500px;">
    <q-form
        @submit="onSubmit"
        style="display: flex;flex-direction: column;align-items: center;margin-top: 50px;"
    >
      <q-input
          filled
          style="width: 400px"
          v-model="email"
          label="Email *"
          hint="您的电子邮箱"
          lazy-rules
          type="email"
          :rules="[ val => val && val.length > 0 || '请输入电子邮箱']"
      />

      <div>
        <q-btn color="black"  label="继续" stack stretch type="submit"
               style="width: 200px;padding-top: 5px;padding-bottom: 5px;margin-top: 40px;"/>
      </div>
    </q-form>
  </div>
</div>
</template>

<style scoped lang="scss">
.forget-box{
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}
</style>